package com.example.ovulationperiodtracker.fragment;


import static android.content.Context.VIBRATOR_SERVICE;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Vibrator;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.afollestad.materialdialogs.MaterialDialog;
import com.example.ovulationperiodtracker.Allactivity.AccountsActivity;
import com.example.ovulationperiodtracker.Allactivity.BackupActivity;
import com.example.ovulationperiodtracker.Allactivity.CycleLenghtActivity;
import com.example.ovulationperiodtracker.Allactivity.HuaiYunActivity;
import com.example.ovulationperiodtracker.Allactivity.JingLengthActivity;
import com.example.ovulationperiodtracker.Allactivity.LanguageActivity;
import com.example.ovulationperiodtracker.Allactivity.MoodsActivity;
import com.example.ovulationperiodtracker.Allactivity.NotificationsActivity;
import com.example.ovulationperiodtracker.Allactivity.OvulationActivity;
import com.example.ovulationperiodtracker.Allactivity.PeriodLengthActivity;
import com.example.ovulationperiodtracker.Allactivity.PillsActivity;
import com.example.ovulationperiodtracker.Allactivity.PinInsertActivity;
import com.example.ovulationperiodtracker.Allactivity.PregnancyActivity;
import com.example.ovulationperiodtracker.Allactivity.RestoreActivity;
import com.example.ovulationperiodtracker.Allactivity.SettingsActivity;
import com.example.ovulationperiodtracker.Allactivity.ShowHideActivity;
import com.example.ovulationperiodtracker.Allactivity.SplashActivity;
import com.example.ovulationperiodtracker.Allactivity.SplashScreen;
import com.example.ovulationperiodtracker.Allactivity.SymptomsActivity;
import com.example.ovulationperiodtracker.Allactivity.UnitsActivity;
import com.example.ovulationperiodtracker.R;
import com.example.ovulationperiodtracker.adapter.MineAdapter;
import com.example.ovulationperiodtracker.databinding.FragmentCalendarBinding;
import com.example.ovulationperiodtracker.databinding.FragmentMineBinding;
import com.example.ovulationperiodtracker.model.MineSet;
import com.example.ovulationperiodtracker.model.Note;
import com.example.ovulationperiodtracker.model.Settings;
import com.example.ovulationperiodtracker.model.User;
import com.example.ovulationperiodtracker.periodadepter.SettingAdapter;
import com.example.ovulationperiodtracker.utils.JCGSQLiteHelper;
import com.example.ovulationperiodtracker.utils.MyLog;
import com.example.ovulationperiodtracker.view.ComfirDialog;
import com.example.ovulationperiodtracker.view.NoteUtils;
import com.necer.base.BaseFragment;
import com.necer.base.NBaseAdapter;
import com.tencent.mmkv.MMKV;

import java.util.ArrayList;
import java.util.List;

public class MineFragment extends BaseFragment<FragmentMineBinding> {


    private final MMKV mmkv = MMKV.defaultMMKV();

    Integer[] imgid = {
            Integer.valueOf(R.mipmap.ic_durata_mestruazioni),
            Integer.valueOf(R.mipmap.ic_durata_ciclo),
            Integer.valueOf(R.mipmap.ic_ovulazione2),
            Integer.valueOf(R.mipmap.ic_lock_white_48dp),
            Integer.valueOf(R.mipmap.ic_visibility_white_48dp),
            Integer.valueOf(R.mipmap.ic_notifications_white_48dp),
            Integer.valueOf(R.mipmap.ic_sintomi),
            Integer.valueOf(R.mipmap.ic_smile),
            Integer.valueOf(R.mipmap.ic_pill),
            Integer.valueOf(R.mipmap.ic_gravidanza),
            Integer.valueOf(R.mipmap.ic_backup_white_48dp),
            Integer.valueOf(R.mipmap.ic_settings_backup_restore_white_48dp),
            Integer.valueOf(R.mipmap.ic_person_add_white_48dp),
            Integer.valueOf(R.mipmap.ic_unita_di_misura2),
            Integer.valueOf(R.mipmap.ic_translate_white_48dp),
            Integer.valueOf(R.mipmap.ic_grade_white_48dp),
            Integer.valueOf(R.mipmap.ic_share_white_48dp),
            Integer.valueOf(R.mipmap.ic_refresh_white_48dp)};

    ListView listSettings;

    @Override
    public FragmentMineBinding createBinding(LayoutInflater inflater, ViewGroup container) {
        return FragmentMineBinding.inflate(inflater);
    }

    @Override
    protected void onCreated() {

    }


    @Override
    public void onResume() {
        super.onResume();


        List<MineSet> mineSetList = new ArrayList<>();
        mineSetList.add(new MineSet("经期长度", "设置默认经期长度", NoteUtils.getJingLength() + "天"));
        mineSetList.add(new MineSet("周期长度", "设置默认周期长度", NoteUtils.getPeriodLength() + "天"));
        mineSetList.add(new MineSet("排卵与易孕期", "设置黄体期长度", NoteUtils.getHuangTiQi() + "天"));
        mineSetList.add(new MineSet("安全设置", "设置保密密码", TextUtils.isEmpty(NoteUtils.getPin()) ? "关闭" : "打开"));
        mineSetList.add(new MineSet("提醒设置", "设置经期、排卵等提醒", ""));
        mineSetList.add(new MineSet("怀孕设置", "开启预产期倒计时", ""));
        mineSetList.add(new MineSet("删除全部数据", "删除全部数据并重启应用", ""));


        MineAdapter mineAdapter = new MineAdapter();
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(context));
        binding.recyclerView.setAdapter(mineAdapter);
        mineAdapter.setData(mineSetList);

        mineAdapter.setOnItemClickListener(new NBaseAdapter.OnItemClickListener<MineSet>() {
            @Override
            public void onItemClick(MineSet item, int position) {
                if (position == 0) {
                    startActivity(new Intent(context, JingLengthActivity.class));
                } else if (position == 1) {
                    startActivity(new Intent(context, CycleLenghtActivity.class));
                } else if (position == 2) {
                    startActivity(new Intent(context, OvulationActivity.class));
                } else if (position == 3) {
                    startActivity(new Intent(context, PinInsertActivity.class));
                } else if (position == 4) {
                    startActivity(new Intent(context, NotificationsActivity.class));
                } else if (position == 5) {
                    startActivity(new Intent(context, HuaiYunActivity.class));
                } else if (position == 6) {
                    new ComfirDialog(context, "确认删除所有数据吗？")
                            .setOnClickYesNoListener(new ComfirDialog.OnClickYesNoListener() {
                                @Override
                                public void onClickYes() {
                                    mmkv.clearAll();
                                    Intent intent = new Intent(context, SplashActivity.class);
                                    startActivity(intent);
                                    getActivity().finish();
                                }
                            }).show();
                }
            }
        });

    }


}
